package zaphod.toy.hitincreaser.internal;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URL;


public class Reader extends Thread
{

    private final String location;
    private final int iteration;
    private final int interval;
    
    /**
     * interval is in milliseconds
     * @param location
     * @param iteration
     * @param interval
     */
    public Reader( String location, int iteration, int interval )
    {
        this.location = location;
        this.iteration = iteration;
        this.interval = interval;

    }


    @Override
    public void run()
    {
        try
        {
            for ( int i = 0; i < iteration; i++ )
            {
                final URL site = new URL( location );
                final BufferedReader in =
                        new BufferedReader( new InputStreamReader(
                                site.openStream(), "utf-8" ) );

                final StringBuilder sb = new StringBuilder();
                String inputLine, result;

                while ( (inputLine = in.readLine()) != null )
                    sb.append( inputLine );
                in.close();

                result = sb.toString();
                result.toString();
            }
        }
        catch ( Exception e )
        {
            e.printStackTrace();
        }
        try
        {
            Thread.sleep( interval );
        }
        catch ( InterruptedException e )
        {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

}
